Note: you don't need to concern yourself with this information until you reach week 5 in the course.

In this series of 4 short programming assignments, you will complete the development of your own MP3 encoder. These assignments are optional and do not count towards your final grade but we strongly believe that "getting your hands dirty" is a lot of fun. You will see that all the theory you have learned in class, from Fourier transform to filter design, from sampling to quantization, comes beautifully together in this application. In the end, you will be the proud owner of your own MP3 encoder. You can use to encode your files, which can be played back with any MP3 player available commercially.

Rest assured that you will not have to implement all the details of the encoder: we will provide you with a framework where all the boring parts and the minutiae are already taken care of. You will only have to complete small portions of the code here and there -- and we will guide you in the process. These programming assignments require you to use Python and if you are not familiar with Python, we invite you to check the tutorial we prepared. Currently, the assignment uses Python 2.7; since most of the code you need to write is basically numerical programming, there will be no major problem if you're an adept of Python 3.

Getting started

Follow these simple steps to get started with the programming assignments:

To learn about MP3 encoding, start by watching the video "MP3 encoder" explaining the history and the inner workings of the MP3 encoder.

Download the following zip file containing a a set of assignment-related files and folders:

Unzip the archive in the location of your choice; this location will be your "base station" to write and test the four parts of the programming homework.

Testing your code locally

Before submitting your answers, you can test the code locally by executing the following commands in a Python shell:

>> import check_assignment as ca
>> ca.check_assignment1()
>> ca.check_assignment2()
>> ca.check_assignment3()
>> ca.check_assignment4()

Or run the following in a terminal shell.

>> ipython check_assignment.py

For assignment 2, a plot of the filter bank can be obtained in the following way:

>> ca.check_assignment2(plot=True)

Submitting your answers

When you are satisfied with your code, submit it like so: in a shell run

>> python generate_submission.py N

where N is the assignment number (1, 2, 3, or 4). The above statement will generate a text file called 'resN.txt' (again, N=1, 2, 3, or 4); use the "My submission' tab to submit the file.

Encoding a file with the final MP3 encoder

To encode a WAVE file, run the program with the following command line arguments:

>> python encoder.py inwavfile.wav [outmp3file] bitrate

Supported bitrates are 64 kbps to 448 kbps in 32 kbps steps (e.g. 64, 128, 256,...), with lower bitrates indicating a higher the compression ratio (and therefore lower quality). If outmp3file is omitted, the same filename as input file is used, but with .mp3 extension. If there is an error reading the WAVE file, maybe its format is not supported by the WavRead class (currently only standard integer PCM WAVE files are supported).

We provide you with two sample WAVE input files, sampled at 44100Hz: 'sine.wav' - a stereo composed of 440 and 880 Hz sine waves, and 'saxophone.wav'. Try for instance

>> python encoder.py samples/sine.wav samples/sine.mp3 320

Please be patient! The encoder is designed so that the code is understandable, but the price to pay is that it runs rather slowly!